#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int S = 59050;
const int N = 2e4+10;
const int inf = 0x3f3f3f3f;
const int M = 2.5e4+10;

bool vis[N],ins[N];

int dep[N],c[N],ppow[12],p[N],n,m,u,v,f[15][S],h[N],cnt;
ll ans;
struct edge{int v,nxt;}e[M<<1];

void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;}

inline int bit(int x,int t){return (x / ppow[t]) % 3;}

inline void upd(int &x,int y){x = min(x,y);}

void dfs(int x){
	vis[x] = ins[x] = 1; int tt = 0; memset(f[dep[x]],0x3f,ppow[dep[x]+1]+1<<2);
	for(int i = h[x],y;i;i = e[i].nxt)
		if(ins[y = e[i].v]) p[++tt] = y;
	if(dep[x]){
		for(int k = 0;k < ppow[dep[x]];k++){
			int No = 0,Yes = k;
			for(int i = 1;i <= tt;i++){
				if(bit(k,dep[p[i]]) == 2) No = 1;
				if(bit(k,dep[p[i]]) == 0) Yes += ppow[dep[p[i]]];
			}
			upd(f[dep[x]][k+ppow[dep[x]]*No],f[dep[x]-1][k]);
			upd(f[dep[x]][Yes+ppow[dep[x]]*2],f[dep[x]-1][k]+c[x]);
		}
	}else{
		f[dep[x]][0] = 0;
		f[dep[x]][1] = inf;
		f[dep[x]][2] = c[x];
	}
	for(int i = h[x],y;i;i = e[i].nxt){
		if(vis[y = e[i].v]) continue;
		dep[y] = dep[x] + 1; dfs(y);
		for(int k = 0;k < ppow[dep[x]+1];k++)
			f[dep[x]][k] = min(f[dep[y]][k+ppow[dep[y]]],f[dep[y]][k+2*ppow[dep[y]]]);
	}
	ins[x] = 0;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	for(int i = 1;i <= n;i++) c[i] = in;
	for(int i = 1;i <= m;i++){
		u = in,v = in; link(u,v); link(v,u);
	}
	for(int i = (ppow[0] = 1);i <= 10;i++) ppow[i] = ppow[i-1] * 3;
	for(int i = 1;i <= n;i++)
		if(!vis[i]){
			dfs(i);
			ans += min(f[0][1],f[0][2]);
		}
	printf("%lld\n",ans);
	return 0;
}

